import bs4

def test_replace():
    fd = open('test.html')
    soup = bs4.BeautifulSoup(fd, 'lxml')

    t_pres = soup.find_all('pre')
    for t_pre in t_pres:
        t_pre.replace_with("{% codeblock %}")

    print(soup.prettify())

if __name__ == "__main__":
    test_replace()
